package com.shanghaionstar.user.service;

import android.content.Context;

import com.onstar.cn.api.UsersService;
import com.onstar.cn.common.util.CommonUtil;
import com.onstar.cn.common.util.Constants;
import com.onstar.cn.framework.annotation.http.HeadsValue;
import com.onstar.cn.framework.annotation.http.Request;
import com.onstar.cn.framework.mvp.base.core.BaseService;
import com.onstar.cn.framework.network.HttpInjectUtils;
import com.onstar.cn.framework.network.entity.RequestEntity;
import com.onstar.cn.framework.network.enumtype.HttpAccept;
import com.onstar.cn.framework.network.enumtype.HttpMethod;
import com.onstar.cn.framework.network.enumtype.Language;
import com.onstar.cn.framework.utils.GsonHelper;
import com.onstar.cn.mag.joinme.RegisterRequestEntity;
import com.onstar.cn.smart.BaseResponse;
import com.shanghaionstar.utils.ApplicationUtil;
import com.shanghaionstar.utils.NetConnectUtil;

/**
 * Created by 7828wc on 16/7/1.
 */
public class ChangeContactService extends BaseService<BaseResponse> {
    private Context context;
    private String province, city, address, code = "";

    public ChangeContactService(Context context) {
        this.context = context;
    }

    @Override
    @Request(heads = @HeadsValue(accept = HttpAccept.JSON, language = Language.AUTO), method = HttpMethod.PUT)
    public RequestEntity getRequestEntity() {
        RequestEntity requestEntity = NetConnectUtil.getAuthRequestEntity(context);
        UsersService publicService = new UsersService(Constants.CURRENT_SERVER_URL);

        RegisterRequestEntity codeEntity = new RegisterRequestEntity();
        codeEntity.setAccountNumber(ApplicationUtil.getInstance().getAccountId());
        codeEntity.setProvince(province);
        codeEntity.setCity(city);
        codeEntity.setAddress1(address);
        codeEntity.setZip(code);
        publicService.getPhoneAndnumber(requestEntity,codeEntity);
        requestEntity = HttpInjectUtils.injectHttp(getClass(), "getRequestEntity", requestEntity);
        return requestEntity;
    }

    public void setUserInfo(String province, String city, String address,String code) {
        this.province = province;
        this.city = city;
        this.address = address;
        this.code = code;
    }

    @Override
    public BaseResponse jsonToBean(String json) {
        if (!CommonUtil.isNull(json))
            return GsonHelper.fromJson(json,BaseResponse.class);
        else return null;
    }
}
